package com.bdqn.t320.servlet;

import com.bdqn.t320.pojo.SysUser;
import com.bdqn.t320.service.SysUserService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/ListServlet")
public class ListServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        System.out.println("ListServlet");
        ServletContext context = getServletContext();
        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
        //从容器中获得bean
        SysUserService sysUserService = (SysUserService) ctx.getBean("sysUserServiceImp");
        List<SysUser> userListBiz = sysUserService.getUserListBiz();
        for (SysUser sysUser : userListBiz) {
            System.out.println(sysUser);
        }
    }
}
